﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Registeranalyse.aspx.cs" Inherits="RegisterWeb.Manager.StatisticalAnalysisCenter.Registeranalyse" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>     
      <link href="../../css/main.css" rel="stylesheet" type="text/css" />
    <link href="../../js/jquery-easyui-1.2.6/themes/gray/easyui.css" rel="stylesheet" type="text/css" />
    <link href="../../js/jquery-easyui-1.2.6/themes/icon.css" rel="stylesheet" type="text/css" />
    <script src="../../js/jquery-easyui-1.2.6/jquery-1.7.2.min.js" type="text/javascript"></script>
    <script src="../../js/jquery-easyui-1.2.6/jquery.easyui.min.js" type="text/javascript"></script>
    <script src="../../js/jquery-easyui-1.2.6/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
		<script type="text/javascript">

		    var options = {
		        chart: {
		            renderTo: 'container'
		            //		                type: 'column'
		        },
		        title: {
		            text: '历史挂号信息统计'
		        },
		        subtitle: {
		            text: '信息统计'
		        },
		        xAxis: {
		    },
		    yAxis: {
		        min: 0,
		        title: {
		            text: '挂号数量'
		        },
		        labels: {
		            formatter: function () {
		                return this.value;
		            }
		        }
		    },
		    legend: {
		        layout: 'vertical',
		        backgroundColor: '#FFFFFF',
		        align: 'left',
		        verticalAlign: 'top',
		        x: 100,
		        y: 70,
		        floating: true,
		        shadow: true
		    },
		    tooltip: {
		        formatter: function () {
		            var tu = document.getElementsByName("tu")[0].value;
		            if (tu == "3") {
		                return '<b>' + this.point.name + '</b>: ' + this.percentage.toString() + ' %';
		            }
		            else
		                return '' + this.x + ':  挂号数量'+ this.y;
		        }
		    },
		    plotOptions: {
		        column: {
		            pointPadding: 0.2,
		            borderWidth: 0
		        }
		    },
		    series: [{
		        name: '挂号数量'
		    }]
		};
		$(function () {
		    var cdata = [];
		    var i = 0;
		    var flag = 0;
		    var chart;
		    var cdata1 = [];
		    var xdata = [];
		    //	    var type = document.getElementsByName("type")[0].value;
		    var sdate = document.getElementsByName("date1")[0].value;
		    var edate = document.getElementsByName("date2")[0].value;
		    var departments = document.getElementsByName("departments")[0].value;
		    var rfoutpatientype = document.getElementsByName("rfoutpatientype")[0].value;

		    $.post("ashx/RegisteranalyseService.ashx", { "action": "1", "startData": sdate, "endData": edate, "rfoutpatientype": rfoutpatientype, "departments": departments }, function (data, textStatus) {
		        if (textStatus == "success") {
		        
		            dataments = $.parseJSON(data);
		            //       flag = 1;
		            var da = new Array();
		            var total = 0;
		            for (i = 0; i < dataments.length; i++) {
		                //  alert(dataments[i].xdata);
		                cdata[i] = parseFloat(dataments[i].ydata);
		                xdata[i] = dataments[i].xdata;              //    alert("flag");	         
		            }
		            options.series[0].data = da;
		        }
		        else {
		            alert("AJAX返回错误");
		        }
		        options.chart.type = 'column'; options.series[0].data = cdata;

		        options.xAxis.categories = xdata;

		        chart = new Highcharts.Chart(options);

		    });




		    $('#type').combobox({
		        url: 'ashx/TimeJson.ashx',
		        editable: false,
		        valueField: 'val',
		        textField: 'text',
		        onSelect: function (record) {
		            var type = document.getElementsByName("type")[0].value;
		      
		            if (type == "4" || type == "5") {
		                $("#timeInput").show();
		         
		            }
		            else {
		                $("#timeInput").hide();
		            
		            }
		        }
		    });

		    $("#date2").datebox({
		        currentText: '今天',
		        closeText: '关闭',
		        disabled: false,
		        formatter: formatDate1
		    });

		    $("#date1").datebox({
		        currentText: '今天',
		        closeText: '关闭',
		        disabled: false,
		        formatter: formatDate2
		    });

		    $('#tu').combobox({
		        url: 'ashx/TuJson.ashx',
		        editable: false,
		        valueField: 'val',
		        textField: 'text',
		        onSelect: function (record) {
		            var cdata = [];
		            var i = 0;
		            var flag = 0;
		            var chart;
		            var cdata1 = [];
		            var xdata = [];
		            var tu = document.getElementsByName("tu")[0].value;
		            var type = document.getElementsByName("type")[0].value;
		            var sdate = document.getElementsByName("date1")[0].value;
		            var edate = document.getElementsByName("date2")[0].value;
		            var departments = document.getElementsByName("departments")[0].value;
		            var rfoutpatientype = document.getElementsByName("rfoutpatientype")[0].value;
		            //          rfoutpatientype
		            //  alert(type);

		            //		        alert("asdass");
		            //		        alert("234");
		            $.post("ashx/RegisteranalyseService.ashx", { "action": type, "startData": sdate, "endData": edate, "rfoutpatientype": rfoutpatientype, "departments": departments }, function (data, textStatus) {
		                if (textStatus == "success") {
		             
		                    dataments = $.parseJSON(data);
		                    //       flag = 1;
		                    var da = new Array();
		                    var total = 0;
		                    if (tu == "3") {
		                        for (i = 0; i < dataments.length; i++) {
		                            total = total + parseFloat(dataments[i].ydata);
		                        }
		                    }
		                    for (i = 0; i < dataments.length; i++) {
		                        if (tu == "3") {
		                            //    alert("12355656");
		                            da[i] = new Array();
		                            da[i][0] = dataments[i].xdata;
		                            da[i][1] = parseFloat(dataments[i].ydata) / total;
		                            //      alert("aaa");
		                        }
		                        else {
		                            //  alert(dataments[i].xdata);
		                            cdata[i] = parseFloat(dataments[i].ydata);
		                            xdata[i] = dataments[i].xdata;
		                            //    alert("flag");
		                        }
		                    }

		                    options.series[0].data = da;
		                }
		                else {
		                    alert("AJAX返回错误");
		                }

		                if (tu == "1") {
		                    options.chart.type = 'column'; options.series[0].data = cdata;
		                }
		                else if (tu == "2") {
		                    options.chart.type = 'area';
		                   options.series[0].data = cdata;
		                }
		                else if (tu == "3") {
		                    options.chart.type = 'pie';
		                }
		                options.xAxis.categories = xdata;
		              
		          
		                 
		                    chart = new Highcharts.Chart(options);
		          
		          
		            });
		        }
		    });

		});

		function formatDate1(v) {
		    if (v instanceof Date) {
		        var year = v.getFullYear();
		        var month = v.getMonth() + 1;
		        var day = v.getDate();
		        var flag = 1;
		        var type = document.getElementsByName("type")[0].value;
		        if (type == "4") {
		            if (year % 4 == 0 && year % 100 != 0) {
		                flag = 0;
		            }
		            if (month == "1" || month == "3" || month == "5" || month == "7" || month == "8" || month == "10" || month == "12") {
		                day = 31;
		            }
		            else if (month == "2") {
		                if (flag == 1)
		                    day = 28;
		                else
		                    day == 29;
		            }
		            else {
		                day = 30;
		            }
		            if (month < 10) {
		                month = '0' + month;
		            }
		            if (day < 10) {
		                day = '0' + day;
		            }
		            return year + '-' + month + '-' + day;
		        }
		        else if (type == "5") {
		            month = '12';
		            day = '31';
		            return year + '-' + month + '-' + day;

		        }
		    }
		}
		function formatDate2(v) {
		    if (v instanceof Date) {
		        var year = v.getFullYear();
		        var month = v.getMonth() + 1;
		        var day = v.getDate();
		        var flag = 1;
		        var type = document.getElementsByName("type")[0].value;
		        if (type == "4") {
		            day = 1;
		            if (month < 10) {
		                month = '0' + month;
		            }
		            if (day < 10) {
		                day = '0' + day;
		            }
		            return year + '-' + month + '-' + day;
		        }
		        else if (type == "5") {
		            month = '01';
		            day = '01';
		            return year + '-' + month + '-' + day;

		        }
		    }

		}


		function draw() {
		    var cdata = [];
		    var i = 0;
		    var flag = 0;
		    var chart;
		    var cdata1 = [];
		    var xdata = [];
		    var tu = document.getElementsByName("tu")[0].value;
		    var type = document.getElementsByName("type")[0].value;
		    var sdate = document.getElementsByName("date1")[0].value;
		    var edate = document.getElementsByName("date2")[0].value;
		    var departments = document.getElementsByName("departments")[0].value;
		    var rfoutpatientype = document.getElementsByName("rfoutpatientype")[0].value;

		    $.post("ashx/RegisteranalyseService.ashx", { "action": type, "startData": sdate, "endData": edate, "rfoutpatientype": rfoutpatientype, "departments": departments }, function (data, textStatus) {
		        if (textStatus == "success") {
		      
		            dataments = $.parseJSON(data);
		            //       flag = 1;
		            var da = new Array();
		            var total = 0;
		            if (tu == "3") {
		                for (i = 0; i < dataments.length; i++) {
		                    total = total + parseFloat(dataments[i].ydata);
		                }
		            }
		            for (i = 0; i < dataments.length; i++) {
		                if (tu == "3") {
		                    //    alert("12355656");
		                    da[i] = new Array();
		                    da[i][0] = dataments[i].xdata;
		                    da[i][1] = parseFloat(dataments[i].ydata) / total;
		                    //      alert("aaa");
		                }
		                else {
		                    //  alert(dataments[i].xdata);
		                    cdata[i] = parseFloat(dataments[i].ydata);
		                    xdata[i] = dataments[i].xdata;
		                    //    alert("flag");
		                }
		            }

		            options.series[0].data = da;
		        }
		        else {
		            alert("AJAX返回错误");
		        }

		        if (tu == "1") {
		            options.chart.type = 'column'; options.series[0].data = cdata;
		        }
		        else if (tu == "2") {
		            options.chart.type = 'area';
		         options.series[0].data = cdata;
		        }
		        else if (tu == "3") {
		            options.chart.type = 'pie';
		        }
		        options.xAxis.categories = xdata;
		    

		            chart = new Highcharts.Chart(options);
		        
		     
		    });
		}
		</script>
</head>
<body>
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>

    <form id="form1" runat="server">
<div  class="easyui-panel" title="挂号统计分析" style="width:auto;height:550px" collapsible="true"
    >
    <div id="tb" style=" margin-left:80px; margin-top:20px; width:870px;"> 
    <div style=" float:left; width:430px;">
            
		     	科室名: 
		        	<input id="departments" name="departments" class="easyui-combobox" style="width:70px"
					url="ashx/DepartmentsService.ashx"
					valueField="Departments_ID" textField="Departments_Name" panelHeight="auto"> 
                    门诊类型: 
	    		 <input   id="OutpatientType"   name="rfoutpatientype"  class="easyui-combobox" style="width:70px"
					url="ashx/ParametersService.ashx?type=regType"
					valueField="SystemParameter_ID" textField="SystemParameter_Name" panelHeight="auto">            
    查询时间:
                <input  id="type" name="type"   class="easyui-combobox"   panelHeight="auto" style="width:100px;"  required="true">   

</div>
                <div id="timeInput" style="display:none;margin:auto;float:left; width:340px;">         
               添加时间: <input  id="date1" name="date1"  class="easyui-datebox" style="width:110px"  required="true"> 
			   到: <input  id="date2" name="date2"  class="easyui-datebox" style="width:110px" required="true"> </div>


                <a href="#" class="easyui-linkbutton" iconCls="icon-search" onclick="draw()">查询</a>
                 </div>  
                 

               <div style="  float:right;  margin-right:100px;" >
               图形:   <input id="tu" name="tu"  class="easyui-combobox"  panelHeight="auto" style="width:70px;" panelHeight="auto">
                  <%--  <option value="1">柱形图</option>
                    <option  value="2">折线图</option>
                    <option   value="3">饼形图</option>
                </select>--%>
               
          </div>
 
                                         
  <div id="container" style="min-width: 400px; height: 400px;  margin-top:30px; margin-left:50px; margin-right:50px;"></div>
  </div>
    </form>
</body>
</html>

